package com.hsnn.medstgmini.trading.pur.dao.impl;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.hibernate.Query;
import org.hibernate.SQLQuery;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.transform.Transformers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.hsnn.medstgmini.base.dict.dao.impl.BaseHibernateDAO;
import com.hsnn.medstgmini.dao.HibernateSqlUtil;
import com.hsnn.medstgmini.trading.pur.dao.OrderNotConfirmDteailDao;
import com.hsnn.medstgmini.trading.pur.model.OrderDetailStatus;
import com.hsnn.medstgmini.trading.pur.model.OrderPackStatus;
import com.hsnn.medstgmini.trading.pur.model.form.OrderPack;
import com.hsnn.medstgmini.trading.pur.model.form.OrderPackage;
import com.hsnn.medstgmini.trading.pur.model.form.PurOrderInfoForm;
import com.hsnn.medstgmini.util.AreaUtil;
import com.hsnn.medstgmini.util.DateUtil;
import com.hsnn.medstgmini.util.Pagination;
import com.hsnn.medstgmini.util.ParseDate;
import com.hsnn.medstgmini.util.PinYin;

@Repository
public class OrderNotConfirmDteailDaoImpl extends BaseHibernateDAO implements OrderNotConfirmDteailDao{
     
	
	@Resource(name = "sessionFactory")
	private SessionFactory sessionFactory;
	@Autowired
	private HibernateSqlUtil dao;
	@Override
	public Pagination getPurOrderNotConfirmDteailList(Pagination page) {
		// TODO Auto-generated method stub
		return null;
	}
	@Override
	public void delete(List<OrderPack> list) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void update(List<OrderPack> list) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public Pagination getOrdersDetailListByProComp(Pagination page) {
		// TODO Auto-generated method stub
		return null;
	}
	
	/**
	 * 
	 *@category 医疗机构获取未审核的订单
	 *@author 王立志
	 *@date 2016年4月10日
	 *@param page
	 */
	public Pagination getPurOrderNotConfirmDteailList1(Pagination page) {
		StringBuffer sql = new StringBuffer()
		.append("SELECT t.order_code orderCode,t.pro_price proPrice,t.pro_count,(t.pro_price*t.pro_count) as buyprice,")
		.append(" a.del_count,(a.del_count*t.pro_price) as delPrice, ")
		.append(" a.recp_count,(t.pro_price*a.recp_count) as recpPrice, ")
		.append(" t.goods_code,t.drug_code,t.qualityspec_name,t.form_name,t.spec_name,t.factor,t.unit_name, ")
		.append(" t.material_name,t.prod_compname,t.prod_compcode,")
		.append(" t.is_longtime_plan,t.order_status, t.pro_price_limit ")
		.append(" from pur_orderinfo t    ")
		.append(" left join pur_delorderinfo a on a.order_code=t.order_code ")
		.append(" where t.order_pack_id=:orderPackId");
	PurOrderInfoForm form = (PurOrderInfoForm) page.getForm();
	 Map<String, Object> params = new HashMap<String, Object>();
	params.put("orderPackId", form.getOrderPackId());
	if (StringUtils.isNotBlank(form.getGoodsCode())) {
	 sql.append(" and t.goods_code=:goodsCode");
	 params.put("goodsCode", form.getGoodsCode());
	}
	if (StringUtils.isNotBlank(form.getBakDrugFlag())) {
	 sql.append(" and t.is_longtime_plan = :bakDrugFlag");
	 params.put("bakDrugFlag", form.getBakDrugFlag());
	}
	if (StringUtils.isNotBlank(form.getOrderStatus())) {
	sql.append(" and t.order_status=:orderStatus");
	params.put("orderStatus", form.getOrderStatus());
	}
	if (StringUtils.isNotBlank(form.getDrugCode())) {
	 sql.append(" and t.drug_code=:drugCode");
	 params.put("drugCode", form.getDrugCode());
	}
	if (StringUtils.isNotBlank(form.getDrugName())) {
	if (PinYin.isPinYin(form.getDrugName().trim())) {
		sql.append(" and t.drug_name_spel like :drugName");
		params.put("drugName", "%"
				+ form.getDrugName().trim().toUpperCase() + "%");
	} else {
		sql.append(" and t.drug_name like :drugName");
		params.put("drugName", "%" + form.getDrugName().trim() + "%");
	   }
	}
	if (StringUtils.isNotBlank(form.getCompName())) {
	sql.append(" and t.prod_compname like :compName");
	params.put("compName", "%" + form.getCompName().trim() + "%");
	}
	return  page;
	}
	@Override
	public void save(List<OrderPack> list) {
		// TODO Auto-generated method stub
		
	}

	
}
